import React, { Component } from 'react'

class TableRow extends Component {
  
  static propTypes = {
    data: React.PropTypes.object.isRequired,
    columns: React.PropTypes.array.isRequired,
    command: React.PropTypes.object.isRequired
  }

  static defaultProps = {
    data: [],
    columns: [],
    command: []
  }

  render() {
    let data = this.props.data
    let columns = this.props.columns
    let command = this.props.command && this.props.command.command

    return (
      <tr>
        {columns.map(config => {
          return <td key={Math.random()}>{data[config.name]}</td>
        })}
        <td>
          {command.map(item => {
            return <a className="btn btn-link btn-xs" key={Math.random()} onClick={this.props.onClick.bind(this, item.name, data)}>{item.text}</a>
          })}
        </td>
      </tr>
    )
  }

}

export default TableRow

